<template>
  <MyCard title="年龄比例">
    <div class="charts" ref="charts"></div>
  </MyCard>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
const charts = ref();

onMounted(() => {
  // 获取echarts类的实例
  const myCharts = echarts.init(charts.value);
  const option = {
    tooltip: {
      trigger: 'item',
    },
    legend: {
      top: 'center',
      right: '5',
      orient: 'vertical',
      textStyle: {
        color: 'white',
        fontSize: 12,
      },
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        padAngle: 5,
        itemStyle: {
          borderRadius: 10, //圆角
          // borderWidth: 5, //线宽
          // borderColor: '#bfa',//线条颜色
        },
        label: {
          show: true,
          position: 'inside',
          color: '#fff',
        },

        labelLine: {
          show: false,
        },
        data: [
          { value: 1048, name: '军事' },
          { value: 735, name: '新闻' },
          { value: 580, name: '娱乐' },
          { value: 484, name: '财经' },
          { value: 456, name: '直播' },
          { value: 1253, name: '游戏' },
          { value: 300, name: '教育' },
        ],
        //调整图形图标的位置
        grid: {
          left: 0,
          top: 0,
          right: 0,
          bottom: 0,
        },
      },
    ],
  };
  // 设置实例的配置项
  myCharts.setOption(option);
});
</script>

<style lang="scss" scoped>
.charts {
  flex: auto;
}
</style>
